<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>hash</title>
</head>
<body>
    <div>
        <a href="#/hash1">hash1</a>
        <a href="#/hash2">hash2</a>
        <a href="#/hash3">hash3</a>
    </div>
</body>
<script>
window.location.hash = 'hash'; // 初始化hash字符串

let hash = window.location.hash; // 获取当前 hash 值

// 监听hash变化
window.addEventListener('hashchange', function(event){ 
    console.log('===current hash===')
    console.log(window.location.hash)
    console.log('new url====='+ event.newURL); // hash 改变后的新 url
    console.log('old url====='+ event.oldURL)// hash 改变前的旧 url
},false)
</script>
</html>